package com.bgs.service.impl;

import com.bgs.entity.User;
import com.bgs.mapper.UserMapper;
import com.bgs.pojo.CollectionsVo;
import com.bgs.pojo.FootprintVo;
import com.bgs.pojo.UserVo;
import com.bgs.service.UserService;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class UserServiceImpl  implements UserService {
    @Autowired
    private  UserMapper userMapper;
    @Override
    public List<User> load3(Integer riderId) {
        List<User> users = userMapper.load3(riderId);
        return users;
    }

    @Override
    public User load(Integer userId) {
        User user = userMapper.load(userId);
        return user;
    }

    @Override
    public String hqyzm(String useremail) throws EmailException {
        HtmlEmail email1 =new HtmlEmail();
        email1.setHostName("smtp.163.com");
        email1.setCharset("utf-8");
        email1.addTo(useremail);
        email1.setFrom("bfc20179445@163.com","星空GC");
        email1.setAuthentication("bfc20179445@163.com","YBGDPCUESZIPNDDF");
        email1.setSubject("验证消息");
        int a= new Random().nextInt(99999)+100000;
        String s ="";
        s="您的验证码是"+a;
//        email1.setMsg(s);
//        email1.send();
        String b = Integer.toString(a);
        return b;
    }

    @Override
    public void updateemail(String userId, String userEmail2) {
         userMapper.updateemail(userId,userEmail2);
    }

    @Override
    public void updatepayment(String userId, String payment1) {
        userMapper.updatepayment(userId,payment1);
    }

    @Override
    public UserVo getUserLogon(String phone, String password) {
        return userMapper.getUserLogon(phone,password);
    }

    @Override
    public List<CollectionsVo> loadcoll(Integer userId) {
        List<CollectionsVo> loadcollections = userMapper.loadcoll(userId);
        return loadcollections;
    }

    @Override
    public void updatestate(Integer userId, Integer collectionsId) {
        userMapper.updatestate(userId,collectionsId);
    }

    @Override
    public List<FootprintVo> loadfoot(Integer userId) {
        List<FootprintVo> footprintVos = userMapper.loadfoot(userId);
        return footprintVos;
    }

    @Override
    public void updatestates(Integer userId, Integer footprintId) {
        userMapper.updatestates(userId,footprintId);
    }
}